package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.entity.Container;
import com.example.springboot.entity.vo.ContainerVO;
import com.example.springboot.service.AdminContainerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: jyf2000jyf
 * @Date: 2022/5/23
 * @Time: 22:57
 * @Email: 904593011@qq.com
 * @Description:
 **/
@RestController
@RequestMapping("admin/container")
public class AdminContainerController {

    @Autowired
    AdminContainerService adminContainerService;

    @GetMapping("page")
    public Result indexByPage(@RequestParam Integer pageNum,
                              @RequestParam Integer pageSize,
                              @RequestParam String yard) {
        pageNum = (pageNum - 1) * pageSize;
        List<Container> data;
        Integer total;
        if (yard == null || "".equals(yard)){
            data = adminContainerService.findAll(pageNum, pageSize, Integer.valueOf(0));
            total = adminContainerService.getAmount(Integer.valueOf(0));
        }else {
            data = adminContainerService.findAll(pageNum, pageSize, Integer.valueOf(yard));
            total = adminContainerService.getAmount(Integer.valueOf(yard));
        }
        return Result.success(new ContainerVO(data, total));
    }
}
